<template>
	<div class="content">
		<div class='div'>
			<div class='circle' v-show='isCircle' :class="{circle1:circleStatus,circle2:!circleStatus}">{{ circle_text }}</div>
			<div class='top'>
				<div class='title'>
					●营养分析
				</div>
				<span>总热量</span>{{ total_heat.toFixed(2) }}kcal<br>
				<span>蛋白质</span>{{ total_protein.toFixed(2) }}g<br>
				<span>脂肪</span>{{ total_fat.toFixed(2) }}g<br>
				<span>碳水化合物</span>{{ total_carbohydrate.toFixed(2) }}g<br>
				<span>数据来源</span> 
				<block v-for='item in nameList'>{{ item.name }} * {{ item.num }} 
				  <span style='color:green;display:inline;margin-left:8px' @click='detail(item)'>详情、</span>
				</block><br>
			</div>
			<div class='bottom'>
				<div class='title'>
					●运动建议
				</div>
				<div class='top'>
					<div>
						<div><img src='@/static/img/go.png'></div>
					</div>
					<div>
						<div><img class='run' src='@/static/img/run.png'></div>
					</div>
					<div>
						<div><img src='@/static/img/ride.png'></div>
					</div>
					<div>
						<div><img src='@/static/img/room.png'></div>
					</div>
				</div>
				<div class='bottom'>
					<div>
						<p>走路</p>
						<p>{{ total_walk }}分钟</p>
					</div>
					<div>
						<p>跑步</p>
						<p>{{ total_run }}分钟</p>
					</div>
					<div>
						<p>骑行</p>
						<p>{{ total_run }}分钟</p>
					</div>
					<div>
						<p>办公</p>
						<p>{{ total_indoor }}分钟</p>
					</div>
				</div>
			</div>
		</div>
		<div class="search">
			<button class='btn' @click='search'>开始匹配</button>
		</div>
		<ul class='showView'>
			<li>
				<input type="text" v-model='name'/>
			  <input type="text" v-model='num'/>
				<span @click='del'>清空</span>
			  <span @click='add'>增加</span>
			</li>
			<li>【订单在此处显示，未匹配到则不显示】</li>
			<li v-for='item in ddList'>
				{{ item.name }} * {{ item.num }}
			</li>
		</ul>
		<div class='modal' v-show='isModal'>
			<div class='content'>
				<p>营养分析</p>
				<ul>
					<li v-for='item in detailData'>
						<p><span>名称</span>{{ item.name }}</p>
						<p><span>主食材</span>{{ item.main }}</p>
						<p><span>卡路里</span>{{ item.heat }}kcal</p>
						<p><span>蛋白质</span>{{ item.protein }}g</p>
						<p><span>脂肪</span>{{ item.fat }}g</p>
						<p><span>碳水化合物</span>{{ item.carbohydrate }}g</p>
						<p><span>卡路里占比</span>脂肪({{ item.source.fat }}%) 、蛋白质({{ item.source.protein }}%) 、碳水化合物({{ item.source.carbohydrate }}%)</p>
						<p><span>运动建议</span>走路({{ item.walk }}分钟) 、跑步({{ item.run }}分钟) 、骑车({{ item.run }}分钟) 、室内办公({{ item.indoor }}分钟)</p>
						<p><span>健康分析</span>{{ item.effect }}</p>
					</li>
				</ul>
				<p @click='close'>关闭</p>
			</div>
		</div>
		<a href='javascript:;' style='margin-left: 2.5%' @click='isShowDish=!isShowDish'>点击查看可分析菜品</a>
		<ul class='supportView' v-if='isShowDish'>
			<li>目前支持匹配菜品<span style='color:red'>{{ dishList.length }}</span>个(可添加多个菜品)：</li><br>
			<li v-for='item in dishList'>{{ item.name }}</li>
		</ul>
	</div>
</template>

<script>
	import dishJson from './dish.json'
	export default {
		data(){
			return{
				isShowDish: false,
				resultData: [],
				total_heat: 0,
				total_protein: 0,
				total_fat: 0,
				total_carbohydrate: 0,
				total_walk: 0,
				total_run: 0,
				total_indoor: 0,
				name: '五香牛肉',
				num: 1,
				circle_text: '',
				isCircle: false,
				circleStatus: true,
				dishList: dishJson,
					// {
					// 	"name": "",
					// 	"heat": ,
					// 	"protein": ,
					// 	"fat": ,
					// 	"carbohydrate": ,
					// 	"walk": ,
					// 	"run": ,
					// 	"indoor": ,
					// 	"source": {
					// 		"fat": ,
					// 		"carbohydrate": ,
					// 		"protein": 
					// 	}
					// 	"main": "",
					// "effect": "",
					// }
				// （总行数 - 3） / 15 = 菜品数量
				ddList: [],
				nameList: [],
				detailData: [],
				isModal: false
			}
		},
		onLoad(){
			console.log(dishJson)
		},
		methods:{
			del(){
				this.ddList = []
				this.name = ''
			},
			add(){
				this.ddList.push({
					name: this.name,
					num: this.num
				})
			},
			detail(item){
				this.dishList.filter(items=>{
					if(item.name == items.name){
						this.detailData.push(items)
					}
				})
				this.isModal = true
			},
			close(){
				this.detailData = []
				this.isModal = false
			},
			search(){
				if(this.ddList.length == 0){
					this.circle_text = '未识别';
					this.circleStatus = false;
					this.isCircle = true;
				}else{
					this.ddList.map(item=>{
						this.dishList.map(items=>{
							if(items.name == item.name){
								this.nameList.push({
									name: items.name,
									num: item.num
								})
								this.total_heat += items.heat * item.num
								this.total_protein += items.protein * item.num
								this.total_fat += items.fat * item.num
								this.total_carbohydrate += items.carbohydrate * item.num
								this.total_walk += items.walk * item.num
								this.total_run += items.run * item.num
								this.total_indoor += items.indoor * item.num
								this.circle_text = '已识别';
								this.circleStatus = true;
								this.isCircle = true;
							}else{
								if(this.nameList.length == 0){
									this.circle_text = '未识别';
									this.circleStatus = false;
									this.isCircle = true;
								}
							}
						})
					})
				}
			}
		}
	}
</script>

<style lang='scss'>
.supportView{
	width: 95%;
	padding: 10px 0;
	list-style-type: none;
	margin-left: 2.5%;
	border: 1px solid rgba(176,196,222,.3);
	border-radius: 8px;
	li:nth-child(n+2){
		display: inline-block;
		width: 33.3%;
	}
}
.circle1{
	background-color: #008080;
}
.circle2{
	background-color: red;
}
.circle{
	width: 100px;
	height: 100px;
	border-radius: 50%;
	position: absolute;
	top: 60px;
	right: 15px;
	color: white;
	display: flex;
	justify-content: center;
	align-items: center;
	font-size: 20px;
	letter-spacing: 2px;
	font-family: 'Times New Roman', Times, serif;
	box-shadow: 0px 0px 10px #778899;
}
.modal{
	width: 100%;
	height: 100vh;
	background-color: rgba(0,0,0,.6);
	position: fixed;
	z-index: 99;
	left: 0;
	top: 0;
	display: flex;
	justify-content: center;
	align-items: center;
	.content{
		width: 90%;
		border: 1px solid rgba(176,196,222,.5);
		background-color: white;
		border-radius: 8px;
		position: relative;
		font-size: 14px;
		span{
			width:85px;
			color:rgba(119,136,156,.6);
			margin-right: 16px;
			display:inline-block;
			text-align-last:justify;
			text-align:justify;
		}
		>p:first-child{
			width: 100%;
			height: 40px;
			line-height: 40px;
			font-size: 20px;
			font-weight: bold;
			text-align: center;
			letter-spacing: 2px;
			border-bottom: 1px solid rgba(176,196,222,.5);
		}
		>p:last-child{
			width: 100%;
			height: 40px;
			line-height: 40px;
			font-size: 16px;
			font-weight: bold;
			text-align: center;
			border-top: 1px solid rgba(176,196,222,.5);
			letter-spacing: 2px;
			color: #007AFF;
		}
		ul{
			width: 90%;
			padding: 5px 10px;
		}
		li{
			list-style-type: none;
			line-height: 30px;
			color: #778899;
		}
	}
}
.showView{
	width: 95%;
	padding: 10px 0;
	list-style-type: none;
	margin-left: 2.5%;
	margin-bottom: 40px;
	li:nth-child(n+2){
		margin-top: 10px;
		line-height: 30px;
	}
	li:first-child{
		width: 100%;
		height: 40px;
		display: flex;
		align-items: center;
		input{
			width: 40%;
			height: 40px;
			border: 1px solid #ccc;
		}
		span{
			width: 20%;
			line-height: 40px;
			text-align: center;
			border: 1px solid #ccc;
			border-radius: 5px;
		}
		span:last-child{
			color: white;
			background-color: rgba(0,128,128,1);
		}
	}
	li:nth-child(n+3){
		border-bottom: 1px solid rgba(176,196,222,.5);
		color: red;
	}
}
.search{
	width: 100%;
	margin: 20px 0;
	.btn{
		width: 95%;
		height: 50px;
		line-height: 50px;
		background-color: #007AFF;
		color: white;
		font-weight: bold;
		font-size: 22px;
		letter-spacing: 5px;
	}
}
.title{
	width: 100%;
	height: 50px;
	line-height: 50px;
	letter-spacing: 3px;
	font-weight: bold;
}
.div{
	width: 95%;
	margin-left: 2.5%;
	margin-top: 20px;
	border: 1px solid #ccc;
	border-radius: 5px;
	color:rgba(112,128,144,1);
	box-sizing: border-box;
	padding: 0 10px 10px;
	position: relative;
	.top{
		width: 100%;
		height: 55%;
		line-height: 28px;
		span{
			width:100px;
			color:rgba(119,136,156,.6);
			margin-right: 16px;
			display:inline-block;
			text-align-last:justify;
			text-align:justify;
		}
	}
	.bottom{
		width: 100%;
		height: 45%;
		.top{
			width: 100%;
			display: flex;
			justify-content: space-between;
			>div{
				width: 5rem;
				height: 3rem;
				display: flex;
				justify-content: center;
				div{
					width:3rem;
					height:3rem;
					border-radius:10px;
					background-color:rgba(247,246,249,1);
					display:flex;
					justify-content:center;
					align-items:center;
					img{
						width: 2rem;
						height: 2rem;
					}
					.run{
						width:1.6rem !important;
						height:1.6rem !important
					}
				}
			}
		}
		.bottom{
			width: 100%;
			display: flex;
			justify-content: space-between;
			div{
				width: 5rem;
				height: 3rem;
				line-height: 1.7rem;
				text-align: center;
			}
		}
	}
}
</style>
